package asn.match.dao;

import java.util.List;

import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import asn.match.model.Like;

@Repository("like")
@PersistenceContext(type = PersistenceContextType.EXTENDED)
@Transactional
public class LikeDaoImpl implements LikeDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void addLike(Like like) {
		this.sessionFactory.getCurrentSession().save(like);
	}

	@Override
	public void updateLike(Like like) {
		this.sessionFactory.getCurrentSession().saveOrUpdate(like);
	}

	@Override
	public void deleteLike(Like like) {
		this.sessionFactory.getCurrentSession().delete(like);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Like> findAllLikes() {
		return (List<Like>) this.sessionFactory.getCurrentSession().createQuery("from Like like").list();
	}

	@Override
	public Like findLikeById(Integer likeId) {
		return (Like) this.sessionFactory.getCurrentSession().get(Like.class, likeId);
	}

}
